from mxupy import IM, EntityXControl
import OBEvolutionAI as obe
import bigOAINet as bigo
import hashlib


class AssistantControl(EntityXControl):
    class Meta:
        model_class = bigo.User

    def register(self, username, realname, password, num, email, phone, schoolId, title, majorfield, bio):
        """
        助教注册方法
        """
        # 对密码进行SHA256加密
        hashed_password = hashlib.sha256(password.encode('utf-8')).hexdigest()
        
        # 创建用户
        if (im := bigo.UserControl.inst().add(
            {   
                "username": username,
                "nickname": username,
                "realname": realname,
                "password": hashed_password,
                "email": email,
                "phone": phone,
                "role": "assistant",
                "num": num,
                "isActive": 0  # 助教默认未激活，需要管理员审核激活
            }
        )).error:
            return im
        userId = im.data.userId
            
        return im